<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%String path = request.getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="UTF-8">
	<title>${tableComment}</title>
	<link rel="stylesheet" type="text/css" href="<%=path %>/static/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=path %>/static/easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=path %>/static/easyui/demo.css">
	<script type="text/javascript" src="<%=path %>/static/jquery/jquery.min.js"></script>
	<script type="text/javascript" src="<%=path %>/static/easyui/jquery.easyui.min.js"></script>
</head>
<body>
	
	<table id="dg"></table>
	<div class="easyui-dialog"  closed="true" id="Window" data-options="title:'${tableComment}',width:'700',height:'400'">
    	
    </div>
	<script type="text/javascript">
		$(function(){
			$('#dg').datagrid({
				url: '/generator/auto/datagrid/${tableName}',
				method: 'get',
				fit:true,
				
				columns:[[
					<#list cols as col> 
	   					{field:'${col.colName}',title:'${col.colComment}'}
	   					<#if col_has_next>,</#if>
					</#list>
				]],
				toolbar: [{
					iconCls: 'icon-add',
					text:'新增',
					handler: function(){add();}
				},'-',{
					iconCls: 'icon-edit',
					text:'编辑',
					handler: function(){edit();}
				},'-',{
					iconCls: 'icon-del',
					text:'删除',
					handler: function(){del();}
				}],
				onHeaderContextMenu: function(e, field){
					e.preventDefault();
					if (!cmenu){
						createColumnMenu();
					}
					cmenu.menu('show', {
						left:e.pageX,
						top:e.pageY
					});
				}
			});
		});
		var cmenu;
		function createColumnMenu(){
			cmenu = $('<div/>').appendTo('body');
			cmenu.menu({
				onClick: function(item){
					if (item.iconCls == 'icon-ok'){
						$('#dg').datagrid('hideColumn', item.name);
						cmenu.menu('setIcon', {
							target: item.target,
							iconCls: 'icon-empty'
						});
					} else {
						$('#dg').datagrid('showColumn', item.name);
						cmenu.menu('setIcon', {
							target: item.target,
							iconCls: 'icon-ok'
						});
					}
				}
			});
			var fields = $('#dg').datagrid('getColumnFields');
			for(var i=0; i<fields.length; i++){
				var field = fields[i];
				var col = $('#dg').datagrid('getColumnOption', field);
				cmenu.menu('appendItem', {
					text: col.title,
					name: field,
					iconCls: 'icon-ok'
				});
			}
		}
		
		function add(){
			//新增
		}
		function edit(){
			//编辑
			var row = $('#dg').datagrid('getSelected');
			if (row){
				//打开编辑框
				
			}else{
				alert("请先选中一行");
			}
		}
		function del(){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				//提示一哈哈
			}else{
				alert("请先选中一行");
			}
		}
	</script>
</body>
</html>